/**
 * 开发商设置
 */
define(function(require, exports, module) {
    var $ = require("jquery");
    var util = require("util");
    var ui = require("ui");
    var tmpl = require("tmpl");
    require('authorize');
    require("permission");
    var api_prefix = G_CONFIG["api_prefix"] + "/qmyx/para-setting/"; //api前缀
    
    var KfsSetting = {
        init:function(){
            this.bindEvent();
            this.getKfsSetting();
        },
        getKfsSetting:function(){
            var url = api_prefix + "get-kfs-setting";
            util.myAjax({
                url: url,
                type: "GET",
                success: function(json) {
                    if (json.retCode == 0) {
                        var data = json.data;
                        if(data.DeveloperName.length == 1){
                            $('#dev_name').val(data.DeveloperName[0].Value);
                        }
                        if(data.agencyregisterprompt.length == 1){
                            $('#register_prompt').val(data.agencyregisterprompt[0].Value);
                        }
                    }else{
                        ui.showErrTip(json.errMsg);
                    }
                }
            });
        },
        bindEvent:function(){
            var _this = this;
            $("#btn_save").on("click",function(e){
                e.preventDefault();
                _this.saveKfsSetting();
            });
        },
        saveKfsSetting:function(){
            var dev_name = ui.checkField("dev_name", false);
            var register_prompt = ui.checkField("register_prompt", true);
            if(dev_name === false || register_prompt === false){
                return false;
            }
            var url = api_prefix + "save-kfs-setting";
            var data = {
                DeveloperName:dev_name,
                agencyregisterprompt: register_prompt
            };
            util.myAjax({
                url: url,
                type: "POST",
                data: data,
                success: function(json) {
                    if (json.retCode == 0) {
                        ui.showSucTip("操作成功");
                    }else{
                        ui.showErrTip(json.errMsg);
                    }
                }
            });
        }
    };
    module.exports = KfsSetting;
});